package com.school.hjt.schoolclasscard.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.school.hjt.schoolclasscard.R;
import com.school.hjt.schoolclasscard.db.Labours;

import java.util.List;

/**
 * Created by xqx on 2018/1/22.
 *
 */

public class LabourAdapter extends BaseAdapter {
    String[] str1={"MON", "TUE", "WED", "THUR", "FRI", "SAT", "SUN"};
    String[] str={"周一", "周二", "周三", "周四", "周五", "周六", "周日"};
    private Context mContext;
    private List<Labours> list;
    public LabourAdapter(Context mContext, List<Labours> list) {
        this.mContext = mContext;
        this.list = list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHander viewHander;
        if (convertView==null){
            viewHander=new ViewHander();
            convertView= View.inflate(mContext, R.layout.labour_item,null);
            viewHander.tv_week=convertView.findViewById(R.id.tv_week);
            viewHander.tv_strWeek=convertView.findViewById(R.id.tv_strWeek);
            viewHander.tv_Time=convertView.findViewById(R.id.tv_Time);
            viewHander.tv_Class=convertView.findViewById(R.id.tv_Class);
            viewHander.tv_week=convertView.findViewById(R.id.tv_week);
            viewHander.tv_admTeacher=convertView.findViewById(R.id.tv_admTeacher);
            viewHander.tv_labTeacher=convertView.findViewById(R.id.tv_labTeacher);
            convertView.setTag(viewHander);
        }else{
            viewHander= (ViewHander) convertView.getTag();
        }
        Labours labours = list.get(position);
        viewHander.tv_week.setText(str1[Integer.parseInt(labours.getWeek_day())-1]);
        viewHander.tv_Class.setText(labours.classname);
        viewHander.tv_Time.setText(labours.now_date);
        viewHander.tv_strWeek.setText(str[Integer.parseInt(labours.getWeek_day())-1]);
        viewHander.tv_admTeacher.setText("值日行政："+labours.adm_teacher);
        viewHander.tv_labTeacher.setText("值日老师："+labours.lab_teacher);
        return convertView;
    }
    class ViewHander{
        TextView tv_week,tv_strWeek,tv_Time,tv_Class,tv_admTeacher,tv_labTeacher;
    }


}
